package com.test.demos.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.test.demos.pojo.dto.EvaluationsDTO;
import com.test.demos.pojo.entity.Evaluations;
import com.test.demos.pojo.vo.EvaluationsVO;
import com.test.demos.service.EvaluationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.test.demos.utils.Result;

/**
 * 体检评价
 *
 * @author twt
 * @since 2025-04-14 16:26:25
 */
@CrossOrigin
@RestController
@RequestMapping("evaluations")
public class EvaluationsController {

    /**
     * 服务对象
     */
    @Autowired
    private EvaluationsService evaluationsService;

    /**
     * 通过ID查询单条数据
     *
     * @param evaluationId 主键
     * @return 实例对象
     */
    @SaCheckLogin
    @GetMapping("{id}")
    public Result<Evaluations> queryById(@PathVariable("id") Integer evaluationId) {
        return Result.ok(evaluationsService.queryById(evaluationId));
    }

    /**
     * 评价
     *
     * @param dto 实例对象
     * @return 实例对象
     */
    @SaCheckLogin
    @PostMapping
    public Result appraise(@RequestBody EvaluationsDTO dto) {
        evaluationsService.add(dto);
        return Result.ok(dto);
    }

    /**
     * 更新数据
     *
     * @param dto 实例对象
     */
    @SaCheckLogin
    @PutMapping
    public Result update(@RequestBody EvaluationsDTO dto) {
        evaluationsService.update(dto);
        return Result.ok();
    }

    /**
     * 通过主键删除数据
     *
     * @param evaluationId 主键
     * @return 是否成功
     */
    @SaCheckRole("admin")
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id") Integer evaluationId) {
        evaluationsService.deleteById(evaluationId);
        return Result.ok();
    }
    /**
     * 查询全部数据
     */
    @SaCheckRole("admin")
    @GetMapping()
    public Result queryAll() {
        return Result.ok(evaluationsService.queryAll());
    }
}
